package testEvent;

import org.junit.Test;
import junit.framework.*;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import junit.framework.TestCase;
import java.io.*;

import player.*;
import event.*;

public class testEventWindow extends TestCase{

	@Test
	public void testShowPickedEventInfo_1() throws Exception{
		setOutput();
		String expectedOut;
		String question = "Background: Children always go out with make-up, seem like having a relationship. "+ "\n" + 
		"However, mother is a traditional person." + "\n" +
		"She does not like her children falling in love with others when they are young."+ "\n"  +
		"So, daddy, how can you solve this problem?"+"\n";
		String mc = "Answer 1: Tell your children what you are suspecting face-to-face and try to understand the situation first. "+"\n" +
		"Then you will speak out your feeling and analyze about the impact with your children, and give him/her some advices." + "\n\n" + 
		"Answer 2: Contact with the teacher of your children, "+"\n" + 
		"and then kindly request him/her to contact with the parents of the involved student in order to solve the problem.";
		
		String actualResult = this.getOutput();
		
		Player p = new Player();
		EventWindow eW = new EventWindow(p);
		eW.showPickedEventInfo(1);
		
		expectedOut = "You have picked Event 1" + "\n" + question + "\n" + mc + "\n";
		System.out.print(expectedOut);
		System.out.print(actualResult);
		assertEquals(expectedOut, actualResult);
	}
	
	@Test
	public void testShowResult_1() throws Exception{
		ByteArrayOutputStream testOut = new ByteArrayOutputStream();
		PrintStream testOutPrintStream = new PrintStream(testOut);
		System.setOut(testOutPrintStream);

		Player p = new Player();
		EventWindow eW = new EventWindow(p);
		eW.showResult(2, p);
		
		String expectedOut = "Event Stop here.\n**************************************\n";
		assertEquals(expectedOut, testOut.toString());
	}
	
	@Test
	public void testValidPlayerNo_1(){
		PlayerIO pIO = new PlayerIO();
		boolean actual = pIO.validPlayerNo(0);
		boolean expected = false;
		assertEquals(expected, actual);
	}
	
	@Test
	public void testValidPlayerNo_2(){
		PlayerIO pIO = new PlayerIO();
		boolean actual = pIO.validPlayerNo(2);
		boolean expected = true;
		assertEquals(expected, actual);
	}
	
	PrintStream oldPrintStream;
	ByteArrayOutputStream bos;  

	private void setOutput() throws Exception
	{
		oldPrintStream = System.out;
		bos = new ByteArrayOutputStream();  
		System.setOut(new PrintStream(bos)); 
	}
	
	private String getOutput() //throws Exception
	{
		System.setOut(oldPrintStream);
		return bos.toString();
	}
}
